package com.ysd.repository;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.ysd.entity.Consume_log;
import com.ysd.entity.Memeber;

public interface Consume_logRepository extends JpaRepository<Consume_log, Integer> {
	
	@Transactional
	@Modifying
	@Query(value = "insert into consume_log values(null,?1,?2,null,?3)",nativeQuery = true)
	int addConsume(int card_id,String in_time,int read_room);
	@Transactional
	@Modifying
	@Query(value = "select *from consume_log",nativeQuery = true)
	List<Consume_log> selectAll();
	@Transactional
	@Modifying
	@Query(value = "select COUNT(*) FROM consume_log",nativeQuery = true)
	int selectCount();
	
	@Transactional
	@Modifying
	@Query(value = "UPDATE memeber SET `status`=?2 where member_id=?1",nativeQuery = true)
	int updateStatus(int mId,int rId);
	/**
	 * 离开资源室时间
	 * @param mId
	 * @param rId
	 * @return
	 */
	@Transactional
	@Modifying
	@Query(value = "UPDATE consume_log SET out_time=?1 where cousume_log_id=?2",nativeQuery = true)
	int xiuGaiStatus(String outTime,int cId);
	/**
	 * 查询会员状态是否已进入阅读室
	 * @param mId
	 * @param sta
	 * @return
	 */
	@Transactional
	@Modifying
	@Query(value = "SELECT * FROM memeber where member_id=?1 AND STATUS=?2",nativeQuery = true)
	Memeber selOne(int mId,int sta);
	/**
	 * 查询是否有这个会员
	 * @param mId
	 * @return
	 */
	@Transactional
	@Modifying
	@Query(value = "SELECT * FROM memeber where member_id=?1",nativeQuery = true)
	Memeber selOneMemeber(int mId);

}
